//
//  PhotoItemView.m
//  KIASupervisory
//
//  Created by tan_xin on 14-9-22.
//  Copyright (c) 2014年 MyCompany. All rights reserved.
//

#import "PhotoItemView.h"

#define DELETE_BUTTON_WIDTH 22

@implementation PhotoItemView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        _photoImgV = [[UIImageView alloc] initWithFrame:self.bounds];
        _photoImgV.tag = 1001;
        [self addSubview:_photoImgV];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(CGRectGetWidth(frame) - DELETE_BUTTON_WIDTH, 0, DELETE_BUTTON_WIDTH, DELETE_BUTTON_WIDTH);
        [btn setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor whiteColor]];
        btn.alpha  = 0.5;
        [btn addTarget:self action:@selector(willDeleteItem) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = 1002;
        [self addSubview:btn];
    }
    return self;
}

- (void)setPhoto:(UIImage *)photo {
    if ([photo isKindOfClass:[UIImage class]]) {
        _photo = photo;
        
        _photoImgV.image = photo;
    }
}

- (void)willDeleteItem {
    if (_delegate && [_delegate respondsToSelector:@selector(willDeletePhoto:)]) {
        [_delegate willDeletePhoto:self];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
